import { _decorator, AudioSource, Component, Label, log, Node, Sprite, SpriteFrame, tween, Vec3 } from 'cc';
import { DialogViewID } from '../../../components/DialogViewID';
import { DialogViewBase } from '../../base/DialogViewBase';
const { ccclass, property } = _decorator;

@ccclass('Bedroom')
export class Bedroom extends DialogViewBase {
    @property(Node)
    monitor:Node;
    @property(Label)
    captions:Label;
    @property(SpriteFrame)
    spriteFrames:Array<SpriteFrame>=[];
    @property(AudioSource)
    audio:AudioSource;
    protected _dialogViewID:DialogViewID = DialogViewID.bedroom;
    private _inx:number=0;
    start() {
        this.node.getChildByName("Button").active = false;
        this.open();
        this.showtxt();
        this.audio.play();
    }
    open() {
        this.monitor.scale = new Vec3(2,2,2);
        // 使用 tween 来实现动画
        tween(this.monitor)
            .to(20,{scale:new Vec3(1,1,1)})  // 10 秒内将 scale 变为 1
         .call(()=>{
            this.stage2();
         }).start();
    }
    stage2():void{
        this.node.getChildByName("Button").active = true;
    }
    showtxt():void{
        this.captions.string = this.strs[this._inx];
        this._inx++;
        if(this._inx>=this.strs.length)
        {
            this.unscheduleAllCallbacks();
        }
    }
    boom(){
        this.node.getChildByName("Button").active = false;
        this.captions.string = this.str2;
        this.monitor.getComponent(Sprite).spriteFrame = this.spriteFrames[0];
        this.monitor.scale = new Vec3(1,1,1);
           // 使用 tween 来实现动画
           tween(this.monitor)
           .to(20,{scale:new Vec3(5,5,5)}).start()  // 10 秒内将 scale 变为 1
        
    }
    private strs:Array<string> = ["在一个寒冷的新年夜晚，有一个贫穷的小女孩在街上卖核弹",
                "她身穿破旧的麻衣，头戴破帽子，脚穿着破鞋，手里抱着一枚核弹",
                "路人匆匆赶路，没有人理睬她。她冻得双腿直打颤，手指冻得僵硬",
                "她害怕回家，因为家里的父亲会打她,而且家里冷得像风洞一样",
                "她蜷缩在屋檐下的一个角落里,她点燃了手里的核弹，在温暖的火光中全村的人看都看到了他们的奶奶"

        ];
    private str2:string ="这晚上全村的人都看到了她的奶奶"
}


